var mongoose = require('mongoose'),
    uuid = require('uuid'),
    Schema = mongoose.Schema;

const envConfig = require('../../config/env/config_development');

var assessSchema = new Schema({
    assess_id: {type:String},
    customer_name: {type:String},
    customer_headpic: {type:String},
    score: {type:Number},
    msg: {type:String},
    reply: {type:String},
});

var foodSchema = new Schema({
    food_id: {type:String},
    name: {type:String},
    price: {type:String},
    img: {type:String},
    foodType_name: {type:String},
    assess:{type:[assessSchema]},
    merchant_id:{type:String}
}, {
    collection: 'food'
});



// Indexes

// Auto update last update time
foodSchema.pre('update', function () {

});

foodSchema.pre('save', function (next) {
    var food = this;
    var foodId=uuid.v4();
    food.food_id = foodId;
    // food.assess.assess_id = uuid.v4();
    food.img=envConfig.upload.food+foodId+".jpg";
    next();
});

mongoose.model('Food', foodSchema);